package com.hieu.sms.model;

import javax.persistence.Transient;

public abstract class AbstractPersistentEntity implements EntityBean{
	private static final long serialVersionUID = 1L;

	public boolean equals(final Object o) {
	      if (this == o) {
	         return true;
	      }
	      else if (o == null) {
	         return false;
	      }
	      else {
	    	  AbstractPersistentEntity other =(AbstractPersistentEntity)o; 
	         return getId() != null && getId().equals(other.getPrimaryKey());
	      }
	      
	   }

	@Transient
	public abstract Long getId();

	@Transient
	public final Long getPrimaryKey() {
		return this.getId();
	}

	public int hashCode() {
		if (getId() == null) {
			return super.hashCode();
		} else {
			return (this).hashCode() ^ getId().hashCode();
		}
	}

	public String toString() {
		return getClass().getSimpleName() + ": " + getId();
	}
}
